package cn.sc.summer.exception.prometheus;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 类名：PrometheusCustomMonitor指标参数
 *
 * @author a-xin
 * @date 2023/9/1 10:11
 */
@Slf4j
@Component
public class PrometheusCustomMonitor {

    /**
     * 记录请求出错次数
     */
    private Counter requestErrorCount;

    private final MeterRegistry registry;

    @Autowired
    public PrometheusCustomMonitor(MeterRegistry registry) {
        this.registry = registry;
    }

    @PostConstruct
    private void init() {
        log.info("==> Start initialization PrometheusCustomMonitor!");
        requestErrorCount = registry.counter("project_error_total", "project", "error_total");
    }

    public Counter getRequestErrorCount() {
        return requestErrorCount;
    }

}

